<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>props的基本使用方法</title>
</head>
<body>
  <!-- 准备一个容器 -->
  <div id="test"></div>
  <div id="test1"></div>
  <div id="test2"></div>

  <!-- 导入react包 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../js/babel.min.js"></script>
  <script type="text/javascript" src="../js/prop-types.js"></script>

  <script type="text/babel">
  // 创建组件
  class Person extends React.Component{
    // 对标签属性进行必要性以及类型的限制
    static propTypes = {
      name: PropTypes.string.isRequired,  // 限制string类型以及必填性
      age: PropTypes.number,
      sex: PropTypes.string,
    }
    
    // 赋予标签属性默认值
    static defaultProps = {
      sex: "-未知-",
      age: 18
    }

    render(){
      const { name, age, sex } = this.props
      return (
        <div>
          <ul>
            <li>姓名: { name }</li>
            <li>性别: { sex }</li>
            <li>年龄: { age + 1 }</li>
          </ul>
        </div>
      )
    }
  } 

  // 渲染组件到页面
  ReactDOM.render(<Person name="jack"/>, document.getElementById('test'))
  </script>


</body>

</html>